package com.example.springbook;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession session) {
        //1.参数校验
        if (!StringUtils.hasLength(name) || !StringUtils.hasLength(password)) {
            return false;
        }

        //2.从数据库中校验账号密码是否正确
        //3.如果正确，存储Session，返回true
        if ("admin".equals(name) && "admin".equals(password)) {
            //账号密码正确
            session.setAttribute("userName", name);
            return true;
        }
        return false;
    }
}
